package javaLabs.lab1.ListQueue;

import java.io.IOException;

public class QueueScenarioFileFailedException extends IOException {

    private QueueScenarioInputCloseFailedException inputException = null;
    private QueueScenarioOutputCloseFailedException outputException = null;

    public QueueScenarioFileFailedException() {
        super();
    }

    public QueueScenarioFileFailedException(String message) {
        super(message);
    }

    public QueueScenarioFileFailedException(QueueScenarioInputCloseFailedException inputCause, QueueScenarioOutputCloseFailedException outputCause) {
        inputException = inputCause;
        outputException = outputCause;
    }

    public QueueScenarioInputCloseFailedException getInputException () {
        return inputException;
    }

    public QueueScenarioOutputCloseFailedException getOutputException() {
        return outputException;
    }

    @Override
    public String getMessage() {
        String inputMessage = inputException == null ? "" : inputException.getCause().getMessage();
        String outputMessage = outputException == null ? "" : outputException.getCause().getMessage();
        String finalMessage = super.getMessage();
        if (!inputMessage.isEmpty() && !outputMessage.isEmpty()) {
            finalMessage += '\n' + inputMessage + '\n' + outputMessage;
        } else if (!outputMessage.isEmpty()) {
            finalMessage += '\n' + outputMessage;
        } else if (!inputMessage.isEmpty()) {
            finalMessage += '\n' + inputMessage;
        }
        return finalMessage;
    }
}
